/**
 * @Author：ming
 * @Date：2023/10/29 9:14 PM
 * @Filename：Hot238
 */

/**
 * @author ming
 */
public class Hot238 {
    public int[] productExceptSelf(int[] nums) {
        //求出前缀和以及后缀和
        int len = nums.length;
        int[] pre = new int[len+1];
        int[] after = new int[len + 1];
        int[] target = new int[len];
        pre[0]=1;
        after[len]=1;
        for (int i = 1; i <= len; i++) {
            pre[i] =pre[i-1]*nums[i-1];
        }

        for (int i = len-1; i >=0 ; i--) {
            after[i] = after[i+1]*nums[i];
        }

        for (int i = 0; i < len; i++) {
            target[i]=pre[i]*after[i+1];
        }
        return target;
    }
}
